#!/usr/bin/env python
# coding: utf-8

# ## 课堂学习内容
#
# > * 1.高德API-web服务
# > * 2.API经济成本预估（调用量、并发量）
# > * 3.地理编码
#
# ---
#

# # 一、高德API
# ## 1. 地理/逆地理编码
# > * 地理编码/逆地理编码 API 是通过 HTTP/HTTPS 协议访问远程服务的接口，提供结构化地址与经纬度之间的相互转化的能力。
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/georegeo
# > * url = https://restapi.amap.com/v3/geocode/geo?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 请求方式：GET
# > * 必填参数：key,address    可选参数：city,batch,output(返回数据格式类型)

# In[85]:


# 地理编码
import requests
import json
import pandas as pd

# In[86]:


url = 'https://restapi.amap.com/v3/geocode/geo?parameters'
key = 'ae0c311c2c3f4d41b0888860a62888e9'
address = '广东省汕头市潮阳区棉城镇东凤华庭4栋|广东省广州市从化区温泉镇|广东省广州市从化区温泉镇温泉大道中山大学南方学院'
batch = 'true'
params = {
    "key": key,
    "address": address,
    "batch": batch,
    "output": json
}
# positional argument follows keyword argument
# pa 一定要放在前面，keyword argument放在末尾！！！可以

r = requests.get(url, params=params)

# In[87]:


r

# In[88]:


r.content

# In[89]:


r.json()

# In[90]:


r.json()['geocodes'][1]['location']  # 温泉镇

# In[91]:


r.json()['geocodes'][2]['location']  # 学校地理位置

# In[ ]:


# In[101]:


import requests
import json
import pandas as pd


# In[102]:


# 思考：如果有1000个位置？重复代码？
# 函数！？ --> 1.节省代码，重复利用
# 地理编码 => 函数形式
def geocode(key, address, city=None, batch=None, sig=None, output=json, callback=None) -> dict:
    """获取高德API的地理编码"""
    url = "https://restapi.amap.com/v3/geocode/geo?parameters"
    key = "ae0c311c2c3f4d41b0888860a62888e9"
    params = {
        "key": key,
        "address": address,
        "city": city,
        "batch": batch,
        "output": json
    }
    # positional argument follows keyword argument（位置参数放在关键字参数之后）
    # pa 一定要放在前面，keyword argument放在末尾！！！可以
    r = requests.get(url, params=params)
    results = r.json()
    return results


# In[105]:


天河城 = geocode(key="key", address='广东省广州市天河城')
print(天河城)
df_天河城地理编码 = pd.json_normalize(天河城['geocodes'])
display(df_天河城地理编码)
天河城地理编码 = 天河城['geocodes'][0]['location']
print("天河城地理编码:", 天河城地理编码)

# In[162]:


中山大学南方学院 = geocode(key=key, address="广东省广州市中山大学南方学院")
print(中山大学南方学院)
df_中山大学南方学院 = pd.json_normalize(中山大学南方学院)
display(df_中山大学南方学院)
中山大学南方学院地理编码 = 中山大学南方学院["geocodes"][0]["location"]
print("中山大学南方学院:", 中山大学南方学院地理编码)

# In[ ]:


# ### 逆地理编码（上课方法）
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/georegeo
# > * url = https://restapi.amap.com/v3/geocode/regeo?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 请求方式：GET
# > * 必填参数：key,location    可填参数：poitype,radius,extensions,batch,output

# In[101]:


import requests
import json
import pandas as pd

# In[102]:


url = 'https://restapi.amap.com/v3/geocode/regeo?parameters'
key = 'ae0c311c2c3f4d41b0888860a62888e9'
location = '113.679287,23.632575'  # 学校地理位置
extensions = 'all'  # 可选参数extensions,返回基本地址信息、附近 POI 内容、道路信息以及道路交叉口信息。(可与poitype一起使用)
radius = '500m'
params = {
    'key': key,
    'location': location,
    'extensions': extensions,
    #     'poitype':poitype,
    'radius': radius,
    'output': 'json'
}
r = requests.get(url, params=params)

# In[103]:


r.json()

# In[104]:


r.json()['regeocode']['roads']

# In[105]:


# 取多个参数
_roads_ = []
for item in r.json()['regeocode']['roads']:
    #    print(item['name'])
    _roads_.append(item['name'])
_roads_

# In[106]:


# pandas 数据清洗   json_normalize数据规范化
pd.json_normalize(r.json()['regeocode']['roads'])

# In[107]:


pd.json_normalize(r.json()['regeocode']['pois'])

# In[108]:


# 计算该列表中聚贤楼的个数？ 并把他们放在一个新列表中
pd.json_normalize(r.json()['regeocode']['pois'])['name'].to_list()

# In[150]:


## 使用函数
import requests
import json
import pandas as pd


# In[152]:


def regeocode(key, location='113.679287,23.632575', poitype=None, radius=None, extensions="all", batch=False,
              roadlevel=None, sig=None, callback=None, homeorcorp=None) -> dict:
    '''获得高德API逆地理编码'''
    url = 'https://restapi.amap.com/v3/geocode/regeo?parameters'
    key = 'ae0c311c2c3f4d41b0888860a62888e9'
    params = {
        'key': key,
        'location': location,
        'poitype': poitype,
        'radius': radius,
        'extensions': extensions,
        'batch': batch,
        'roadlevel': roadlevel,
        'sig': sig,
        'output': 'json',
        'callback': callback,
        'homeorcorp': homeorcorp
    }
    r = requests.get(url, params=params)
    result = r.json()
    return result


# In[153]:


中大南方 = regeocode(key=key, location="113.679287,23.632575", extensions="all")
print(中大南方)
df_中大南方 = pd.json_normalize(中大南方)
df_中大南方

# ## 2. 路径规划
# > * 1.步行
# > * 2.公车
# > * 3.驾车
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/direction

# ### 2.1 步行
# > * 接口简介：步行路径规划 API 可以规划100KM以内的步行通勤方案，并且返回通勤方案的数据。
# > * url = https://restapi.amap.com/v3/direction/walking?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 请求方式：GET
# > * 必填参数: key,origin,destination    可填参数：sig,output,callback

# In[138]:


import requests
import json
import pandas as pd


# In[157]:


## 封装函数
def walk(key, origin='113.679287,23.632575', destination='113.632403,23.616941', output=json, sig=None,
         callback=None) -> dict:
    '''获取高德API步行路径规划'''
    url = 'https://restapi.amap.com/v3/direction/walking?parameters'
    key = 'ae0c311c2c3f4d41b0888860a62888e9'
    params = {
        "key": key,
        "origin": origin,
        "destination": destination,
        "sig": sig,
        "output": json,
        "callback": callback

    }
    r = requests.get(url, params=params)
    result = r.json()
    return result


# In[167]:


road_walk = walk(key, origin, destination)
print(road_walk)
df_road_walk = pd.json_normalize(road_walk)
df_road_walk

# ### 2.2公车路径规划
#
# > * 1.url：'https://restapi.amap.com/v3/direction/transit/integrated?parameters'
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 2.requests.get
# > * 3.必选参数：key,origin,destination,city
#  可选参数：cityd,extensions,strategy,nightflag,date,time,sig,output,callback

# In[43]:


import requests
import json
import pandas as pd


# In[48]:


# 封装函数


# In[164]:


def bus(key, origin='113.632403,23.616941', destination='113.679287,23.632575', city='广州', cityd=None, extensions=None,
        strategy=None, nightflag=None, date=None, time=None, sig=None, output=json, callback=None) -> dict:
    '''获取高德API公车路径规划'''
    url = 'https://restapi.amap.com/v3/direction/transit/integrated?parameters'
    key = 'ae0c311c2c3f4d41b0888860a62888e9'
    params = {
        "key": key,
        "origin": origin,
        "destination": destination,
        "city": city,
        "cityd": cityd,
        "extensions": extensions,
        "strategy": strategy,
        "nightflag": nightflag,
        "date": date,
        "time": time,
        "sig": sig,
        "callback": callback,
        "output": json
    }
    response = requests.get(url, params=params)
    results = response.json()
    return results


# In[165]:


road_bus = bus(key, origin='113.632403,23.616941', destination='113.679287,23.632575', city='广州')
print(road_bus)
df_road_bus = pd.json_normalize(road_bus)
df_road_bus

# ### 2.2驾车路径规划
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/direction
# > * url = https://restapi.amap.com/v3/direction/driving?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 请求方式：GET
# > * 必填参数：key,origin,destination
#    可选参数：originid,destinationid,origintype,destinationtype,strategy,waypoints,avoidpolygons,avoidroad,province,number,cartype,ferry ,roadaggregation,nosteps,sig,output=json,callback,extensions

# In[172]:


import requests
import json
import pandas as pd


# In[177]:


# 封装函数
def car(key, origin='116.613190,23.269440', destination='113.679287,23.632575', originid=None, destinationid=None,
        origintype=None, destinationtype=None, strategy=None, waypoints=None, avoidpolygons=None, avoidroad=None,
        province=None, number=None, cartype=None, ferry=None, roadaggregation=None, nosteps=None, sig=None, output=json,
        callback=None, extensions=None) -> dict:
    '''获取高德API驾车编码'''
    url = 'https://restapi.amap.com/v3/direction/driving?parameters'
    key = 'ae0c311c2c3f4d41b0888860a62888e9'
    params = {
        "key": key,
        "origin": origin,
        "destination": destination,
        "originid": originid,
        "destinationid": destinationid,
        "origintype": origintype,
        "destinationtype": destinationtype,
        "strategy": strategy,
        "waypoints": waypoints,
        "avoidpolygons": avoidpolygons,
        "province": province,
        "number": number,
        "cartype": cartype,
        "ferry": ferry,
        "roadaggregation": roadaggregation,
        "nosteps": nosteps,
        "sig": sig,
        "callback": callback,
        "extensions": extensions,
        "output": json
    }
    r = requests.get(url, params=params)
    result = r.json()
    return result


# In[178]:


road_car = car(key, origin='116.613190,23.269440', destination='113.679287,23.632575')
print(road_car)
df_road_car = pd.json_normalize(road_car)
df_road_car

# ### 2.3骑行路径规划
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/direction
# > * url = https://restapi.amap.com/v4/direction/bicycling?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 请求方式：GET
# > * 必填参数：key,origin,destination

# In[76]:


import requests
import json
import pandas as pd


# In[77]:


# 封装函数
def bike(key, origin='116.613190,23.269440', destination='116.602392,23.259433') -> dict:
    '''获取高德API骑行路径规划'''
    url = 'https://restapi.amap.com/v4/direction/bicycling?parameters'
    key = 'ae0c311c2c3f4d41b0888860a62888e9'
    params = {
        "key": key,
        "origin": origin,
        "destination": destination
    }
    r = requests.get(url, params=params)
    result = r.json()
    return result


# In[79]:


road_bike = bike(key, origin='116.613190,23.269440', destination='116.602392,23.259433')
print(road_bike)
df_road_bike = pd.json_normalize(road_bike['data'])
df_road_bike

# ### 2.4货车路径规划
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/direction
# > * url = https://restapi.amap.com/v4/direction/truck?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 请求方式：GET
# > * 必填参数：key,origin,destination,size
#    可选参数：originid,originidtype,destinationid,destinationtype,diu,strategy,waypoints,height,width,load,weight,axis,province,number,cartype,avoidpolygons,showpolyline,nosteps

# In[202]:


import requests
import json
import pandas as pd


# In[203]:


def truck(key, origin='116.613190,23.269440', destination='113.679287,23.632575', size=2, originid=None,
          originidtype=None, destinationid=None, destinationtype=None, diu=None, strategy=None, waypoints=None,
          height=None, width=None, load=None, weight=None, axis=None, province=None, number=None, cartype=None,
          avoidpolygons=None, showpolyline=None, nosteps=None) -> dict:
    '''获取高德API货车路径规划'''
    url = 'https://restapi.amap.com/v4/direction/bicycling?parameters'
    key = 'ae0c311c2c3f4d41b0888860a62888e9'
    params = {
        "key": key,
        "origin": origin,
        "destination": destination,
        "size": size,
        "originid": originid,
        "originidtype": originidtype,
        "destinationid": destinationid,
        "diu": diu,
        "strategy": strategy,
        "waypoints": waypoints,
        "height": height,
        "width": width,
        "load": load,
        "weight": weight,
        "axis": axis,
        "province": province,
        "number": number,
        "cartype": cartype,
        "avoidpolygons": avoidpolygons,
        "showpolyline": showpolyline,
        "nosteps": nosteps,
        "output": json
    }

    r = requests.get(url, params=params)
    result = r.json()
    return result


# In[205]:


road_truck = truck(key, origin, destination, size=2)
print(road_truck)
df_road_truck = pd.json_normalize(road_truck)
df_road_truck

# In[ ]:


# ### 2.5距离测量
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/direction
# > * url = https://restapi.amap.com/v3/distance?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 请求方式：GET
# > * 必填参数：key,origin,destination
#    可选参数：type,sig,output,callback

# In[20]:


import requests
import json
import pandas as pd

# In[28]:


url = 'https://restapi.amap.com/v3/distance?parameters'
key = 'ae0c311c2c3f4d41b0888860a62888e9'
origins = '116.613190,23.269440'
destination = '113.679287,23.632575'
params = {
    'key': key,
    'origins': origins,
    'destination': destination,
    'output': 'json'

}
r = requests.get(url, params=params)

# In[29]:


r

# In[30]:


r.json()


# In[86]:


# 封装函数
def distance(key='key', origin='116.613190,23.269440', destination='113.679287,23.632575', type=None, sig=None,
             output='json', callback=None) -> dict:
    '''获取高德API测量距离'''
    url = 'https://restapi.amap.com/v3/distance?parameters'
    key = 'ae0c311c2c3f4d41b0888860a62888e9'
    params = {
        "key": key,
        "origin": origin,
        "destination": destination,
        "type": type,
        "sig": sig,
        "callback": callback,
        "output": json
    }

    r = requests.get(url, params=params)
    result = r.json()
    return result


# In[88]:


car_distance = distance(key='key', origin='116.613190,23.269440', destination='113.679287,23.632575')
print(car_distance)
df_car_distance = pd.json_normalize(car_distance)
df_car_distance

#

# ## 3.行政区域查询
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/district
# > * url = https://restapi.amap.com/v3/config/district?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 请求方式：GET
# > * 必填参数：key
#    可选参数：keywords,subdistrict,page,offset,extensions,filter,callback,output

# In[54]:


import requests
import json
import pandas as pd

# In[49]:


url = 'https://restapi.amap.com/v3/config/district?parameters'
key = 'ae0c311c2c3f4d41b0888860a62888e9'
keywords = '广东'
params = {
    'key': key,
    'keywords': keywords,
    'output': json
}
r = requests.get(url, params)

# In[50]:


r

# In[51]:


r.content

# In[52]:


r.json()


# In[ ]:


# In[63]:


# 封装函数
def district(key, keywords='广州市', subdistrict=None, page=None, offset=None, extensions='base', filter=None,
             callback=None, output=json) -> dict:
    '''获取行政区域'''
    url = 'https://restapi.amap.com/v3/config/district?parameters'
    key = 'ae0c311c2c3f4d41b0888860a62888e9'
    params = {
        "key": key,
        "keywords": keywords,
        "subdistrict": subdistrict,
        "page": page,
        "offset": offset,
        "extensions": extensions,
        "filter": filter,
        "callback": callback,
        "output": json
    }

    r = requests.get(url, params=params)
    result = r.json()
    return result


# In[64]:


行政区域 = district(key, keywords='广州市', extensions='base')
print(行政区域)
df_行政区域 = pd.json_normalize(行政区域["districts"])
df_行政区域

# ## 4.搜索POI
# > * 搜索服务API是一类简单的HTTP接口，提供多种查询POI信息的能力，其中包括关键字搜索、周边搜索、多边形搜索、ID查询四种筛选机制。
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/search
# > * url = https://restapi.amap.com/v3/ip?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 请求方式 GET
# > * 必填参数：key,keywords,types(keywords和types两者至少必选其一)   可选参数：city,citylimit,children,output

# In[19]:


import requests
import json
import pandas as pd

# In[22]:


r.json()

# In[40]:


# 封装函数（数据准备）
key = 'ae0c311c2c3f4d41b0888860a62888e9'


# In[41]:


def POI(keywords, types, city=None, citylimit=None, children=None, page=None, extensions='base', sig=None) -> dict:
    """获取高德API的POI"""
    url = "https://restapi.amap.com/v3/place/text?parameters"
    params = {
        "key": key,
        "keywords": keywords,
        "types": types,
        "city": city,
        "citylimit": citylimit,
        "children": children,
        "page": page,
        "extensions": extensions,
        "output": json
    }
    # positional argument follows keyword argument（位置参数放在关键字参数之后）
    # pa 一定要放在前面，keyword argument放在末尾！！！可以
    r = requests.get(url, params=params)
    results = r.json()
    return results


# In[44]:


汕头_中学 = POI(keywords=None, types="中学", city="汕头市", children=1, extensions="all", page=3)
print(汕头_中学)
df_汕头_中学 = pd.json_normalize(汕头_中学["pois"])
df_汕头_中学

# In[ ]:


# ## 5.IP定位
# > * IP定位是一个简单的HTTP接口，根据用户输入的IP地址，能够快速的帮用户定位IP的所在位置。
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/ipconfig
# > * url = https://restapi.amap.com/v3/ip?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 请求方式 GET
# > * 必填参数：key  可选参数：ip,sig,output

# In[80]:


import requests
import json
import pandas as pd


# In[83]:


def IP(key, ip=None, sig=None, output=json) -> dict:
    '''获取高德API的IP定位'''
    url = " https://restapi.amap.com/v3/ip?parameters"
    key = "ae0c311c2c3f4d41b0888860a62888e9"
    params = {
        "key": key,
        "ip": ip,
        "sig": sig,
        "output": json
    }
    r = requests.get(url, params=params)
    result = r.json()
    return result


# In[85]:


IP定位 = IP(key, ip=None, sig=None, output=json)
print(IP定位)
df_IP定位 = pd.json_normalize(IP定位)
df_IP定位

# In[ ]:


# ## 6.批量请求接口
# > * 批量接口通过用户传入合并后的请求，同时返回多个请求的顺序集合，目前最多支持20个子请求。 返回的顺序与子请求的顺序一致。
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/batchrequest
# > * url = https://restapi.amap.com/v3/batch?key=<用户的key>
# > * key = ae0c311c2c3f4d41b0888860a62888e9

# In[244]:


import requests
import json
import pandas as pd


# In[248]:


def batch(
        url="/v3/place/around?offset=10&page=1&key=5e511d55ece1791b213c4ef41b428738&location=116.315196,39.959971&output=json&radius=100000&types=080000"):
    '''获取高德API批量请求接口'''
    parameters = {
        "key": key,
    }
    body = {
        "ops": [
            {
                "url": '{}'.format(url)
            },
            {
                "url": "/v3/place/around?offset=10&page=1&key=5e511d55ece1791b213c4ef41b428738&location=116.315196,39.959971&output=json&radius=100000&types=080000"
            }
        ]
    }
    response = requests.get("https://restapi.amap.com/v3/batch?", params=parameters, json=body)
    data = response.json()
    return data


batch()

# In[ ]:


# ## 7.静态地图
# > * 静态地图服务通过返回一张地图图片响应HTTP请求，使用户能够将高德地图以图片形式嵌入自己的网页中。用户可以指定请求的地图位置、图片大小、以及在地图上添加覆盖物，如标签、标注、折线、多边形。
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/staticmaps
# > * url = https://restapi.amap.com/v3/staticmap?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 必填参数：key,location,zoom
# 可选参数：size,scale,markers,labels,paths,traffic,sig

# In[54]:


import requests
from PIL import Image
from io import BytesIO


# In[55]:


def staticmap(key, location="113.680117,23.631544", zoom=[1, 17], size=None, scale=1, markers=None, labels=None,
              paths=None, traffic=0, sig=None, output=json) -> dict:  # 中山大学南方学院-综合楼
    '''获取高德API静态地图'''
    url = "https://restapi.amap.com/v3/staticmap?parameters"
    key = "ae0c311c2c3f4d41b0888860a62888e9"
    params = {
        "key": key,
        "location": location,
        "zoom": zoom,
        "size": size,
        "markers": markers,
        "labels": labels,
        "paths": paths,
        "traffic": traffic,
        "sig": sig,
        "output": json
    }
    r = requests.get(url, params=params)
    result = Image.open(BytesIO(r.content))
    return result


# In[59]:


staticmap(key="key", location="113.680117,23.631544", zoom=15)


# In[ ]:


# ## 8.坐标转换
# > * 坐标转换是一类简单的HTTP接口，能够将用户输入的非高德坐标（GPS坐标、mapbar坐标、baidu坐标）转换成高德坐标。
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/convert
# > * url = https://restapi.amap.com/v3/assistant/coordinate/convert?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 必填参数：key,locations
# 可选参数：coordsys,sig,output

# In[60]:


def convert(key, locations="113.679287,23.632575", coordsys=None, sig=None, output=json) -> dict:
    '''获取坐标转换'''
    url = "https://restapi.amap.com/v3/assistant/coordinate/convert?parameters"
    key = "ae0c311c2c3f4d41b0888860a62888e9"
    params = {
        "key": key,
        "locations": locations,
        "coordsys": coordsys,
        "sig": sig,
        "output": json
    }
    r = requests.get(url, params=params)
    result = r.json()
    return result


# In[63]:


坐标转换 = convert(key="key", locations="113.679287,23.632575")
print(坐标转换)
df_坐标转换 = pd.json_normalize(坐标转换)
df_坐标转换


# In[ ]:


# ## 9.天气查询
# > * 天气查询是一个简单的HTTP接口，根据用户输入的adcode，查询目标区域当前/未来的天气情况。
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/weatherinfo
# > * url = https://restapi.amap.com/v3/weather/weatherInfo?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 必填参数：key,city
# 可选参数：extensions,output

# In[86]:


def weather(key, city='广州市', extensions=None, output=json) -> dict:
    '''获取天气查询'''
    url = 'https://restapi.amap.com/v3/weather/weatherInfo?parameters'
    key = 'ae0c311c2c3f4d41b0888860a62888e9'
    params = {
        "key": key,
        "city": city,
        "extensions": extensions,
        "output": json
    }
    r = requests.get(url, params=params)
    result = r.json()
    return result


# In[87]:


weather_inquire = weather(key="key", city="广州市")
print(weather_inquire)
df_weather_inquire = pd.json_normalize(weather_inquire)
df_weather_inquire


# In[ ]:


# ## 10.输入提示
# > * 输入提示是一类简单的HTTP接口，提供根据用户输入的关键词查询返回建议列表。
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/inputtips
# > * url = https://restapi.amap.com/v3/assistant/inputtips?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 必填参数：key,keywords
# 可选参数：type,location,city,citylimit,datatype,sig,output,callback

# In[93]:


def inputtips(key, keywords='海底捞', type=None, location=None, city=None, citylimit="true", datatype="all", sig=None,
              callback=None, output=json) -> dict:
    '''获取高德API提示'''
    url = 'https://restapi.amap.com/v3/assistant/inputtips?parameters'
    key = 'ae0c311c2c3f4d41b0888860a62888e9'
    params = {
        "key": key,
        "keywords": keywords,
        "type": type,
        "location": location,
        "city": city,
        "citylimit": citylimit,
        "datatype": datatype,
        "sig": sig,
        "callback": callback,
        "output": json
    }
    r = requests.get(url, params=params)
    result = r.json()
    return result


# In[94]:


inputtips = inputtips(key="key", keywords="海底捞")
print(inputtips)
df_inputtips = pd.json_normalize(inputtips)
df_inputtips


# In[ ]:


# ## 11.交通态势
# > * 交通态势是一类简单的HTTP接口，提供根据用户输入的内容能够返回希望查询的交通态势情况。
# > * 参考资料：https://lbs.amap.com/api/webservice/guide/api/trafficstatus
# > * url = https://restapi.amap.com/v3/traffic/status/rectangle?parameters
# > * key = ae0c311c2c3f4d41b0888860a62888e9
# > * 必填参数：key,rectangle
# 可选参数：level,extensions,sig,output,callback

# In[99]:


def trafficstatus(key, rectangle='113.679287,23.632575;113.588823,23.547738', level=None, extensions=None, sig=None,
                  callback=None, output=json) -> dict:
    '''获取交通态势'''
    url = 'https://restapi.amap.com/v3/assistant/inputtips?parameters'
    key = 'ae0c311c2c3f4d41b0888860a62888e9'
    params = {
        "key": key,
        "level": level,
        "extensions": extensions,
        "rectangle": rectangle,
        "output": "json"
    }
    response = requests.get(url, params=params)
    data = response.json()
    return data


中大南方_从化客运站交通态势 = trafficstatus("113.679287,23.632575;113.588823,23.547738")
中大南方_从化客运站交通态势

# In[ ]:
sd



